/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2011 Bull S.A.S.
 * Contact: jonas-team@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * --------------------------------------------------------------------------
 * $Id: ProcessorAlarmToNotificationTransformer.java 469 2011-09-30 14:24:46Z guillaume.sauthier $
 * --------------------------------------------------------------------------
 */


package org.osami.gateway.mediator.alarm.internal;

import java.util.ArrayList;
import java.util.List;

import fr.liglab.adele.cilia.Data;
import org.osami.gateway.alarm.IAlarm;
import org.ow2.jasmine.event.beans.JasmineEventNotification;

/**
 * A {@code ProcessorAlarmCreator} is responsible to transform an Alarm into a JASMINe notification.
 *
 * @author Guillaume Sauthier
 */
public class ProcessorAlarmToNotificationTransformer {

    public List<Data> process(List<Data> input) {
        List<Data> result = new ArrayList<Data>();

        if (input != null) {

            // Transform each input OS@mI Alarm into a JASMINe notification
            for (Data data : input) {

                IAlarm alarm = (IAlarm) data.getContent();

                JasmineEventNotification notification = new JasmineEventNotification();
                notification.setId(alarm.getIdentifier());
                notification.setDate(alarm.getDate());
                notification.setLevel(alarm.getSeverity().name());
                notification.setMessage(alarm.getMessage());
                notification.setStatus(false);
                // WARNING: Magic value, do not change it !!!
                notification.setRule("InsertJasmineEventInNotificationDatabase");

                // We can add details if needed
                notification.addDetail("local-identifier", alarm.getIdentifier());
                notification.addDetail("local-send-date", String.valueOf(alarm.getDate().getTime()));

                result.add(new Data(notification));
            }
        }

        return result;
    }
}
